package ${package.Controller}.form;

import java.util.function.Consumer;
import com.justgame.project.cloud.common.query.Query;
import ${package.Entity}.${table.entityName};
import ${cfg.parent}.${package.ModuleName}.query.${entity}Query;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiModel;
import lombok.Data;

/**
*
* ${table.comment!}控制器查询入参传输层
*
* @tableName ${table.name}
* @author ${author}
*/
@Data
@ApiModel(value="${entity}对象传输层", description="${table.comment!}传输层")
public class ${entity}QueryForm{
    @ApiModelProperty("分页：页数")
    private Integer page;
    @ApiModelProperty("分页：条数")
    private Integer size;

    public Consumer<MPJLambdaWrapper<${entity}>> buildCondition(){
        return wrapper -> {
        };
    }

    public ${entity}Query.Select buildSelect(){
        return ${entity}Query.Select.builder()
                    .${table.entityName}()
        <#list cfg.entity.joinTables as joinTable>
                    .${joinTable.alias}()
        </#list>
                    .build();
    }

    public Page<${entity}> buildPage(){
        return new Page<>(Math.max(page,1),Math.max(size,1));
    }

    public ${entity}Query buildListQuery(){
        return ${table.entityName}Query.builder()
                .select(buildSelect().getQueriesArray())
                .condition(buildCondition());
    }

    public ${entity}Query buildPageQuery(){
        return buildListQuery().page(buildPage());
    }
}
